package com.java.ttt.actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.java.ttt.bo.User;
import com.java.ttt.common.TTTConstants;
import com.java.ttt.dao.MoveDao;
import com.opensymphony.xwork2.ActionSupport;

public class MoveAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String cellID;
	private String result = "success";

	@Override
	public String execute() throws Exception {
		MoveDao dao = new MoveDao();
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute(TTTConstants.LOGGED_IN_USER);
		int i = dao.saveMove(user.getUsername(), 1, cellID);
		if (i > 0) {
			return SUCCESS;
		} else {
			return LOGIN;
		}
	}

	public String getCellID() {
		return cellID;
	}

	public void setCellID(String cellID) {
		this.cellID = cellID;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
}
